<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>

</body>
<script>
    var xhr=new XMLHttpRequest();
    xhr.responseType='arraybuffer';
    xhr.onload=function () {
        if (xhr.readyState==4 && xhr.status==200){
           /* var buffer=xhr.response;
            var blob=new Blob([buffer],{type:'audio/mpeg'});
            var url=window.URL.createObjectURL(blob);
            var audio=document.createElement('audio');
            audio.src=url;
            audio.controls='';
            audio.volume=0.03;//声音大小
            document.body.appendChild(audio);
            audio.play();*/
           var aCxt=new AudioContext();//创建一个对象
            aCxt.decodeAudioData(xhr.response,function (buffer) {//解析音频并且回调
                var sNode=aCxt.createBufferSource();//创建音乐节点
                sNode.buffer=buffer;//相当于路径
                sNode.connect(aCxt.destination);//连接扬声器
                sNode.start(0);//从0开始播放
            });
        }
    }

        xhr.open('post','./music/jdbtr.mp3',true);
        xhr.send();

</script>
</html>


























